<?php

class Posts extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    public function getUserPost($userId) {
        $this->db->select('posts.*,user1.firstname p_fname,user1.lastname p_lname,user1.avatar as p_avatar,user2.firstname as c_fname,user2.lastname as c_lname,comments.userId as userIdComment,comments.comment,comments.date');
        $this->db->from('posts');
        $this->db->join('comments', 'posts.id = comments.postId', 'left');
        $this->db->join('users as user1', 'user1.id = posts.userId', 'left');
        $this->db->join('users as user2', 'user2.id = comments.userId', 'left');
        $this->db->where('posts.userId', $userId);
        $query = $this->db->get();
        return $query->result();
    }

    public function insertComment($data) {
        $query = $this->db->insert('comments', $data);
        return $query;
    }

}
